#include<bits/stdc++.h>
#define endl "\n";
#define ll long long
#define all(rq) rq.begin(),rq.end()

using namespace std;
const int INF=0x3f3f3f3f;
ll fpow(ll base,ll pow,ll mod){ //求a的b次方 b可分为一个二级制数
	ll ans=1;
	while(pow){
		if(pow&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		pow>>=1;
	}
	
	return ans;
}

int main(){
	ll n,m,p;
	cin>>n>>m>>p;
	cout<<n<<'^'<<m<<" mod "<<p<<"="<<fpow(n,m,p)<<endl;
	return 0;
}